


import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:huajianshe_app/base/AppNavigator.dart';
import 'package:huajianshe_app/common/AppRouter.dart';
import 'package:huajianshe_app/common/C.dart';
import 'package:huajianshe_app/common/TS.dart';
import 'package:huajianshe_app/common/load_image.dart';
import 'package:huajianshe_app/common/space.dart';
import 'package:huajianshe_app/pages/search/SearchPage.dart';
import 'package:huajianshe_app/widget/ImageWithBadge.dart';
import 'package:huajianshe_app/widget/RoundedCornerWidget.dart';

//仅首页用
class CircleSearchAppBar extends StatelessWidget implements PreferredSizeWidget {

  // final void Function()? onSearch;
  final SearchType searchType;

  const CircleSearchAppBar(this.searchType, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    String title = '', hint = '';
    if (searchType == SearchType.circle) {
      title = '圈子';
      hint = '搜索感兴趣的圈子';
    } else if (searchType == SearchType.lesson) {
      title = '课程';
      hint = '搜索感兴趣的课程';
    }
    return AnnotatedRegion<SystemUiOverlayStyle>(value: SystemUiOverlayStyle.dark,
        child: Material(color: Colors.white,
            child: SafeArea(bottom: false,child: Row(mainAxisSize: MainAxisSize.max, children: [
              W(16),
              Column(mainAxisSize: MainAxisSize.min, children: [
                Text(title, style: TS(21, C.gray1A, fontWeight: FontWeight.bold)),
                H(5),
                RoundedCornerWidget(child: W(0), width: 20, height: 3, radius: 1.5, backgroundColor: C.primary, borderWidth: 0,)
              ],),
              W(13),
              Expanded(child: GestureDetector(onTap: () => search(context),
                  child: RoundedCornerWidget(
                      backgroundColor: C.grayF6, borderColor: Colors.transparent, height: 40, radius: 13,
                      child: Row(mainAxisSize: MainAxisSize.max, children: [
                        W(16),
                        LoadImage('ic_gray_search'),
                        W(12),
                        Text(hint, style: TS(16, C.gray666),)
                      ])
                  )
              )),
              W(8),
              ImageWithBadge('ic_black_notification', num: 1, onPressed: () {print('on press');}),
              W(10)
            ]))
        )
    );
  }

  search(BuildContext context) {
    AppNavigator.push(context, RouteName.SEARCH, arguments: {'searchType': searchType});
  }

  @override
  Size get preferredSize => Size.fromHeight(48);
}